package com.apes.fn.rpt.settle.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @author pengyb
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ExpenditureSummary.CONST_TABLE_NAME)
public class ExpenditureSummary extends BaseModel {
    public static final String CONST_TABLE_NAME = "report_expenditure_summary";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "营业支出", prefix = "1")
    @Comment("流水编号")
    private String id;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @Comment("公司编码")
    private PartyRole company;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "expenditure_type", referencedColumnName = "id")
    @Comment("支出项")
    private Enumeration expenditureType;


    @Comment("统计日期")
    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Column(name = "statistics_date")
    private Date statisticsDate;


    @Column(name = "amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("金额")
    private double amount = 0;

}
